//
//  TVPurchaseCellModel.swift
//  StarTimesON
//
//  Created by Toj on 12/8/22.
//  Copyright © 2022 StarTimes. All rights reserved.
//

import UIKit

class TVPurchaseCellModel: NSObject {
    
    var isLoaded = false
    
    private(set) var id = ""
    // 标题
    private(set) var title = ""
    // 简介信息
    private(set) var brief = ""
   
    private(set) var cellModels: [TVAdditionalCommodityCellModel] = []
    
    var selectedCommodity: TVAdditionalCommodityCellModel?
    private var defaultCommodity: TVAdditionalCommodityCellModel?
    func reset() {
        selectedCommodity = defaultCommodity
    }
    init(additional: TVAdditionalRulesModel) {
        super.init()
        
        var additionals = [TVAdditionalCommodityCellModel]()
        additional.additionalCommoditys.forEach { commodity in
            let cellModel = TVAdditionalCommodityCellModel(commodity: commodity)
            additionals.append(cellModel)
            guard cellModel.isSelected else { return }
            defaultCommodity = cellModel
        }
        cellModels = additionals
        
        id = additional.additionalRuleId
        title = additional.title
        brief = additional.brief
        
        guard selectedCommodity == nil else { return }
        cellModels.first?.isSelected = true
        defaultCommodity = cellModels.first
    }
}
